package com.team7.system.controller;

import com.team7.common.entity.Permission;
import com.team7.common.vo.CommonResult;
import com.team7.common.vo.PermissionVo;
import com.team7.common.vo.RolePermissionVo;
import com.team7.system.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: team7-Object
 * @description:
 * @author: 杨海涛
 * @create: 2021-10-19 10:09
 **/
@RestController
@RequestMapping("/system/permission")
@Api("用户权限的接口")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @ApiOperation("查询用户角色具有的所有权限填充左侧菜单栏")
    @GetMapping("/getAllPermission")
    public CommonResult getAllPermission(){
        return permissionService.getAllPermission();

    }

    @ApiOperation("根据id查询用户角色具有的所有权限，用于角色表中权限分配")
    @GetMapping("/getAllPermissionById")
    public CommonResult getAllPermissionById(){
        return permissionService.findAllPermissionById();
    }

    @ApiOperation("根据roleId查询权限")
    @GetMapping("findPermissionByRoleId/{roleId}")
    public CommonResult findPermissionByRoleId(@PathVariable String roleId){
        return permissionService.findPermissionByRoleId(roleId);
    }

    @ApiOperation("根据id删除菜单及其子菜单")
    @PostMapping("deleteById")
    public CommonResult deleteById(@RequestBody PermissionVo permissionVo){
        return permissionService.deleteById(permissionVo);
    }

    @ApiOperation("新增")
    @PutMapping("insert")
    public CommonResult insert(@RequestBody Permission permission){

        return permissionService.insert(permission);
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public CommonResult update(@RequestBody Permission permission){

        return permissionService.update(permission);
    }

    @ApiOperation("修改用户权限")
    @PostMapping("confirmFenPermission")
    public CommonResult confirmFenPermission(@RequestBody RolePermissionVo rolePermissionVo){
        return permissionService.confirmFenPermission(rolePermissionVo);
    }

    @ApiOperation("根据id查询菜单")
    @GetMapping("findById/{id}")
    public CommonResult finfById(@PathVariable String id){
        return permissionService.findById(id);
    }

    @ApiOperation("查询所有菜单，分页，条件")
    @PostMapping("/findAllByPage/{page}/{limit}")
    public CommonResult findAllByPage(@PathVariable Integer page,@PathVariable Integer limit,@RequestBody PermissionVo permissionVo){
        return permissionService.findAllByPage(page,limit,permissionVo);
    }
}
